define(function(require){
	var main =require('/static/main.js');
	require('/static/ajaxfileupload.js');
	var m = new main();
	function Cont(){
		this.Fun._init();
	}
	Cont.prototype.Fun = {
		TagIds:[],
		_init:function(){
		    this.getlist();
			this.bindEvent();
		},
		bindEvent:function(){
			
		},
		getlist:function(){
	        var param = {};
	        var table1 = $('#datatable1').dataTable({
	        	'ordering':false,
	        	"serverSide": true,
	        	"searching":false,
	        	'bLengthChange': false,
	        	ajax: function (data, callback, settings) {
	                //封装请求参数
	                param.type = 100;
	                param.PageSize = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
	                param.start = data.start;//开始的记录序号
	                param.PageNo = (data.start / data.length)+1;//当前页码
	                //ajax请求数据
	                $.ajax({
	                    type: "POST",
	                    url: "/order/order-list",
	                    cache: false,  //禁用缓存
	                    data: param,  //传入组装的参数
	                    dataType: "json",
	                    success: function (result) {
                    	    var returnData = {};
                            returnData.draw = data.draw;
                            returnData.recordsTotal = result.total;
                            returnData.recordsFiltered = result.total;
                            returnData.data = result.data;
                            callback(returnData);
	                    }
	                });
	            },
				"aoColumns":[
					{"mDataProp": 'OrderId'}, 
					{
						"mDataProp": 'OrderStatus',
						render:function(data){
							var datas = '';
							switch(data){
								case (-1):
									datas = '用户取消';
									break;
								case (-2):
									datas = '管理员作废';
									break;
								case (-3):
									datas = '已失效';
									break;
								case 1000:
									datas = '待支付';
									break;
								case 2000:
									datas = '待发货';
									break;
								case 2100:
									datas = '已报名待参加';
									break;
								case 4000:
									datas = '已发货';
									break;
								case 5000:
									datas = '已完成';
									break;
								case 5100:
									datas = '已关闭';
									break;
							}
							return datas;
                    	}
					}, 
                    {
                    	"mDataProp": 'Title',
			            "sClass": "ll",
                   	},
                    {
                    	"mDataProp": 'CreateTime',
                    	render:function(data){
                    		if(data){
                    			return m.formatTimeAll2(data)
                    		}else{
                    			return '暂无添加时间';
                    		}
                    	}
                	},
                    {"mDataProp": 'TrueName',"sClass": "ll",},
                    {"mDataProp": 'Phone'},
                    {
                    	"mDataProp": 'JoinChannelName',
                    },
                    {	"mDataProp": 'Price',
	               		render:function(data){
							if(!data){
								return '暂无';
							}else{
								return data;
							}
                    	}
                    },
                    {
                    	"mDataProp": 'PaymentMethod',
                    	render:function(data){
							var datas = '';
							switch(data){
								case 100:
									datas = '未支付';
									break;
								case 200:
									datas = '支付宝';
									break;
								case 300:
									datas = '微信';
									break;
								case 400:
									datas = '余额';
									break;
								default:
									datas = '暂无'
							}
							return datas;
                    	}
                   	},
                    {
                    	"mDataProp": 'PayNo',
                    	"sClass": "PayNo",
                    	render:function(data){
							if(data){
                    			return data
                    		}else{
                    			return '暂无';
                    		}
                    	}
               		},
                    {
			            "mDataProp": "OrderId",
			            "sClass": "option_btn",
			            "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
			            	// console.log(arguments);
			                $(nTd).html('<span data-toggle="modal" data-target="#custom-width-modal" data-toggle="tooltip" class="btn_detial" data-id="'+sData+'" data-type="100">查看</span>\
                                            ');

			            }
			        }
				],
	        }).api();
			var table2 = $('#datatable2').dataTable({
	        	'ordering':false,
	        	"serverSide": true,
	        	"searching":false,
	        	'bLengthChange': false,
	        	ajax: function (data, callback, settings) {

	                //封装请求参数
	                param.type = 200
	                param.PageSize = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
	                param.start = data.start;//开始的记录序号
	                param.PageNo = (data.start / data.length)+1;//当前页码
	                //ajax请求数据
	                $.ajax({
	                    type: "POST",
	                    url: "/order/order-list",
	                    cache: false,  //禁用缓存
	                    data: param,  //传入组装的参数
	                    dataType: "json",
	                    success: function (result) {
                    	    var returnData = {};
                            returnData.draw = data.draw;
                            returnData.recordsTotal = result.total;
                            returnData.recordsFiltered = result.total;
                            returnData.data = result.data;
                            callback(returnData);
	                    }
	                });
	            },
				"aoColumns":[
					{"mDataProp": 'OrderId'}, 
					{
						"mDataProp": 'OrderStatus',
						render:function(data){
							var datas = '';
							switch(data){
								case (-1):
									datas = '用户取消';
									break;
								case (-2):
									datas = '管理员作废';
									break;
								case (-3):
									datas = '已失效';
									break;
								case 1000:
									datas = '待支付';
									break;
								case 2000:
									datas = '待发货';
									break;
								case 2100:
									datas = '待参加';
									break;
								case 4000:
									datas = '已发货';
									break;
								case 5000:
									datas = '已完成';
									break;
								case 5100:
									datas = '已关闭';
									break;
							}
							return datas;
                    	}
					}, 
					{
                    	"mDataProp": 'CreateTime',
                    	render:function(data){
                    		if(data){
                    			return m.formatTimeAll2(data)
                    		}else{
                    			return '暂无';
                    		}
                    	}
                	},
					{"mDataProp": 'Title',"sClass": "ll",}, 
					{"mDataProp": 'TrueName',"sClass": "ll",},
                    {"mDataProp": 'Phone'},
                    {	
                    	"mDataProp": 'SubscribeTime',
                    	render:function(data){
                    		if(data){
                    			return m.formatTimeAll2(data)
                    		}else{
                    			return '暂无';
                    		}
                    	}
                    },
                    {
                    	"mDataProp": 'SubscribeObjName',
                	},
                    {
                    	"mDataProp": 'JoinChannel',
                    	render:function(data){
							var datas = '';
							switch(data){
								case 100:
									datas = '微信朋友圈';
									break;
								case 200:
									datas = '微信好友';
									break;
								case 300:
									datas = 'QQ好友';
									break;
								case 400:
									datas = 'QQ空间';
									break;
								case 500:
									datas = '新浪微博';
									break;
								case 600:
									datas = '录入';
									break;
								case 700:
									datas = '现场集客';
									break;
								case 800:
									datas = '引流游戏';
									break;
								default:
									datas = '暂无'
							}
							return datas;
                    	}
                    },
					
                    {
			            "mDataProp": "OrderId",
			            "sClass": "option_btn",
			            "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
			            	// console.log(arguments);
			                $(nTd).html('<span data-toggle="modal" data-target="#custom-width-modal" data-toggle="tooltip" class="btn_detial" data-id="'+sData+'" data-type="200">查看</span>\
                                            ');

			            }
			        }
				],
	        }).api();
			var table3 = $('#datatable3').dataTable({
	        	'ordering':false,
	        	"serverSide": true,
	        	"searching":false,
	        	'bLengthChange': false,
	        	ajax: function (data, callback, settings) {
	                //封装请求参数
	                param.type = 300
	                param.PageSize = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
	                param.start = data.start;//开始的记录序号
	                param.PageNo = (data.start / data.length)+1;//当前页码
	                //ajax请求数据
	                $.ajax({
	                    type: "POST",
	                    url: "/order/order-list",
	                    cache: false,  //禁用缓存
	                    data: param,  //传入组装的参数
	                    dataType: "json",
	                    success: function (result) {
                    	    var returnData = {};
                            returnData.draw = data.draw;
                            returnData.recordsTotal = result.total;
                            returnData.recordsFiltered = result.total;
                            returnData.data = result.data;
                            callback(returnData);
	                    }
	                });
	            },
				"aoColumns":[
					{"mDataProp": 'OrderId'}, 
					{
						"mDataProp": 'OrderStatus',
						render:function(data){
							var datas = '';
							switch(data){
								case (-1):
									datas = '用户取消';
									break;
								case (-2):
									datas = '管理员作废';
									break;
								case (-3):
									datas = '已失效';
									break;
								case 1000:
									datas = '待支付';
									break;
								case 2000:
									datas = '待发货';
									break;
								case 2100:
									datas = '待参加';
									break;
								case 4000:
									datas = '已发货';
									break;
								case 5000:
									datas = '已完成';
									break;
								case 5100:
									datas = '已关闭';
									break;
							}
							return datas;
                    	}
					}, 
					{
                    	"mDataProp": 'CreateTime',
                    	render:function(data){
                    		if(data){
                    			return m.formatTimeAll2(data)
                    		}else{
                    			return '暂无';
                    		}
                    	}
                	},
					{"mDataProp": 'Title',"sClass": "ll",}, 
					{"mDataProp": 'TrueName',"sClass": "ll",},
                    {"mDataProp": 'Phone'},
                    {	
                    	"mDataProp": 'ApplyTime',
                    	render:function(data){
                    		if(data){
                    			return m.formatTimeAll2(data)
                    		}else{
                    			return '暂无';
                    		}
                    	}
                    },
                    {
                    	"mDataProp": 'JoinChannel',
                    	render:function(data){
							var datas = '';
							switch(data){
								case 100:
									datas = '微信朋友圈';
									break;
								case 200:
									datas = '微信好友';
									break;
								case 300:
									datas = 'QQ好友';
									break;
								case 400:
									datas = 'QQ空间';
									break;
								case 500:
									datas = '新浪微博';
									break;
								case 600:
									datas = '录入';
									break;
								case 700:
									datas = '现场集客';
									break;
								case 800:
									datas = '引流游戏';
									break;
							}
							return datas;
                    	}
                    },
                    {
			            "mDataProp": "OrderId",
			            "sClass": "option_btn",
			            "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
			            	// console.log(arguments);
			                $(nTd).html('<span data-toggle="modal" data-target="#custom-width-modal" data-toggle="tooltip" class="btn_detial" data-id="'+sData+'" data-type="300">查看</span>\
                                           ');

			            }
			        }
				],
	        }).api();
			
			// 点击tab
			$('.nav.nav-tabs li a').click(function(){
				var type = parseInt($(this).attr('data-type'));
				if(type == 100){
					$('.search_condition .aaa').html('<span class="input-group-addon">营销类型:</span>\
                                        <select class="input-group-select form-control AdMarketType">\
                                            <option value="">--请选择--</option>\
                                            <option value="100">新品</option>\
                                            <option value="200">团购</option>\
                                        </select>');
				}else{
					$('.search_condition .aaa').html('<span class="input-group-addon tit">预约时间:</span>\
                                        <input type="text" id="StartProTime" name="example-input1-group1" class="form-control StartProTime" placeholder="请输入开始时间" readonly>\
                                        <span class="input-group-addon">至</span>\
                                        <input type="text" id="EndProTime" name="example-input1-group1" class="form-control EndProTime" placeholder="请输入结束时间" readonly>');
					if(type == 200){
						$('.search_condition .tit').html('预约时间:');
					}else{
						$('.search_condition .tit').html('活动时间:');
					}
			        $("#StartProTime").datetimepicker({
			            language: 'zh-CN',
			            format: "yyyy-mm-dd hh:ii",
			            weekStart: 1,
			            todayBtn: 1,
			            autoclose: 1,
			            todayHighlight: 1,
			            startView: 2,
			            forceParse: 0,
			            showMeridian: 1
			        });
			        $("#EndProTime").datetimepicker({
			            language: 'zh-CN',
			            format: "yyyy-mm-dd hh:ii",
			            weekStart: 1,
			            todayBtn: 1,
			            autoclose: 1,
			            todayHighlight: 1,
			            startView: 2,
			            forceParse: 0,
			            showMeridian: 1
			        });
				}
			})
			// 点击搜索
	        $('#btnSearch').click(function(){
	        	param.AdMarketType = $('.AdMarketType option:selected').val();
	        	param.OrderStatus = $('.OrderStatus option:selected').val();
	        	param.Phone = $('.Phone').val();
	        	param.TrueName = $('.TrueName').val();
	        	param.Title = $('.Title').val();
	        	param.StartTime = $('.StartTime').val()
	        	param.EndTime = $('.EndTime').val()
	        	param.AdOrderSearchCD = $('.AdOrderSearchCD').val();

	        	var start = $('.StartProTime').val()
	        	var end = $('.EndProTime').val()

	        	var type = parseInt($('.nav.nav-tabs .active a').attr('data-type'));
	        	param.type = type;
	        	// console.log(type);
	        	if(type == 100){
	        		var table = $('#datatable1').DataTable();
                     table.ajax.reload();
	        	}else if(type == 200){
	        		param.StartSubscribeTime = start;
	        		param.EndSubscribeTime = end;
	        		var table = $('#datatable2').DataTable();
                    table.ajax.reload();
	        	}else if(type == 300){
	        		param.StartActTime = start;
	        		param.EndActTime = end;
	        		var table = $('#datatable3').DataTable();
                    table.ajax.reload();
	        	}
	        })
	        // 点击重置按钮
	        $('#btnRefresh').click(function(){
	        	$('.AdMarketType option,.OrderStatus option').each(function(){
					if(parseInt($(this).val()) == ''){
						$(this).attr('selected',true);
					}else{
						$(this).attr('selected',false);
					}
				})
	        	$('.Phone').val('');
	        	$('.TrueName').val('');
	        	$('.Title').val('');
	        	$('.StartTime').val('');
	        	$('.EndTime').val('');
	        	$('.StartProTime').val('');
	        	$('.EndProTime').val('');
	        	$('.AdOrderSearchCD').val('');
	        })
	        // 点击查看详情
	        $(document).on('click','.btn_detial',function(){
	        	 var id = $(this).attr('data-id');
	        	 var type = parseInt($(this).attr('data-type'));
			     $.ajax({
	        		type: "POST",
					url:'/order/order-detial',
					data:{OrderId:id},
					dataType: "json",
					success:function (ret) {
		               if(ret.IsBizSuccess){
		               		var ret = ret.Model;
		               		var datas = '';
		               		switch(ret.OrderStatus){
								case (-1):
									datas = '用户取消';
									break;
								case (-2):
									datas = '管理员作废';
									break;
								case (-3):
									datas = '已失效';
									break;
								case 1000:
									datas = '待支付';
									break;
								case 2000:
									datas = '待发货';
									break;
								case 2100:
									datas = '已报名待参加';
									break;
								case 4000:
									datas = '已发货';
									break;
								case 5000:
									datas = '已完成';
									break;
								case 5100:
									datas = '已关闭';
									break;
							}
							var PaymentMethod = ''
							switch(ret.PaymentMethod){
								case 100:
									PaymentMethod = '未支付';
									break;
								case 200:
									PaymentMethod = '支付宝';
									break;
								case 300:
									PaymentMethod = '微信';
									break;
								case 400:
									PaymentMethod = '余额';
									break;
								default:
									PaymentMethod = '未支付'
							}
							var Channel = '';
							switch(ret.JoinChannel){
								case 100:
									Channel = '微信朋友圈';
									break;
								case 200:
									Channel = '微信好友';
									break;
								case 300:
									Channel = 'QQ好友';
									break;
								case 400:
									Channel = 'QQ空间';
									break;
								case 500:
									Channel = '新浪微博';
									break;
								case 600:
									Channel = '录入';
									break;
								case 700:
									Channel = '现场集客';
									break;
								case 800:
									Channel = '引流游戏';
									break;
							}
		               		var str = '';
		               		if(ret.Title){
		               			var tit = ret.Title
		               		}else{
		               			var tit = ''
		               		}
		               		str+='<div class="row">\
					                    <div class="col-sm-2 order_detial_des">订单号：</div>\
					                    <div class="col-sm-10 order_detial_cont">'+ret.OrderId+'</div>\
					                </div>\
					                <div class="row">\
					                    <div class="col-sm-2 order_detial_des">订单状态：</div>\
					                    <div class="col-sm-10 order_detial_cont">'+datas+'</div>\
					                </div>\
					                <div class="row">\
					                    <div class="col-sm-2 order_detial_des">下单时间：</div>\
					                    <div class="col-sm-10 order_detial_cont">'+m.formatTimeAll2(ret.CreateTime)+'</div>\
					                </div>'
					                	if(type == 200){
					                		str+='<div class="row">'
					                    	str+='<div class="col-sm-2 order_detial_des">预约时间：</div>'
					                    	str+='<div class="col-sm-10 order_detial_cont">'+m.formatTimeAll2(ret.SubscribeTime)+'</div>'
					                		str+='</div>'
					                	}else if(type == 300){
					                		str+='<div class="row">'
					                    	str+='<div class="col-sm-2 order_detial_des">报名时间：</div>'
					                    	str+='<div class="col-sm-10 order_detial_cont">'+m.formatTimeAll2(ret.ApplyTime)+'</div>'
					                		str+='</div>'
					                	}
					                str+='<div class="row">\
					                    <div class="col-sm-2 order_detial_des">软文标题：</div>\
					                    <div class="col-sm-10 order_detial_cont">'+tit+'</div>\
					                </div>\
					                <div class="row">\
					                    <div class="col-sm-2 order_detial_des">姓名：</div>\
					                    <div class="col-sm-10 order_detial_cont">'+ret.TrueName+'</div>\
					                </div>\
					                <div class="row">\
					                    <div class="col-sm-2 order_detial_des">手机号：</div>\
					                    <div class="col-sm-10 order_detial_cont">'+ret.Phone+'</div>\
					                </div>'
					                str+='<div class="row">\
					                    <div class="col-sm-2 order_detial_des">备注：</div>\
					                    <div class="col-sm-10 order_detial_cont">'+ret.Comment+'</div>\
					                </div>'
					                str+='<div class="row">\
					                    <div class="col-sm-2 order_detial_des">成交渠道：</div>\
					                    <div class="col-sm-10 order_detial_cont">'+Channel+'</div>\
					                </div>'
					                if(type == 100){
					                	// if(ret.PayAccount == 'null'){
					                	// 	var PayAccount = ret.PayAccount;
					                	// }else{
					                	// 	var PayAccount = ret.PayAccount;
					                	// }
					                	// if(ret.PayNo  == null){
					                	// 	var PayNo = ret.PayNo;
					                	// }
					                	// console.log(ret.PayAccount);
					                	var PayAccount = ret.PayAccount ? ret.PayAccount : ''
					                	var PayNo = ret.PayNo ? ret.PayNo : ''
					                	str+='<div class="row">\
								                    <div class="col-sm-2 order_detial_des">下单金额：</div>\
								                    <div class="col-sm-10 order_detial_cont">&yen;'+ret.Price+'</div>\
								                </div>'
								        str+='<div class="row">\
								                    <div class="col-sm-2 order_detial_des">支付方式：</div>\
								                    <div class="col-sm-10 order_detial_cont">'+PaymentMethod+'</div>\
								                </div>\
								        		<div class="row">\
								                    <div class="col-sm-2 order_detial_des">支付账号：</div>\
								                    <div class="col-sm-10 order_detial_cont PayAccount">'+PayAccount+'</div>\
								                </div>\
								                <div class="row">\
								                    <div class="col-sm-2 order_detial_des">支付流水：</div>\
								                    <div class="col-sm-10 order_detial_cont PayNo">'+PayNo+'</div>\
								                </div>'

								        // if(ret.OrderStatus == 1000){
					           //      		$('.PayAccount').hide();
					           //      		$('.PayNo').hide();
					           //      	}else{
					           //      		$('.PayAccount').show();
					           //      		$('.PayNo').show();
					           //      	}
					                }else if(type == 200){
					                	str+='<div class="row">\
								                    <div class="col-sm-2 order_detial_des">预约人员/项目：</div>\
								                    <div class="col-sm-10 order_detial_cont">'+(ret.SubscribeObjName ? ret.SubscribeObjName : '')+'</div>\
								                </div>'
					                }
					                
					        $('.order_detial_all').html(str);
		               }else{
		               		layer.msg(ret.ErrMsg);
		               		return false;
		               }
		            }
	        	 })
	        })





		},

	}
	var a = new Cont();

})